package com.grizz.snake.controller;

public class MovementService {
	public static final int MOVEMENT_DELAY_SLOW = 200;
	public static final int MOVEMENT_DELAY_FAST = 100;
	
	private Mediator mediator;
	private int timeLeft = MOVEMENT_DELAY_SLOW;
	private int delay;
	
	public MovementService(Mediator mediator) {
		this.mediator = mediator;
		delay = timeLeft;
		mediator.register(this);
	}
	
	public void update(int delta){
		if(!mediator.isPaused()){
			timeLeft -= delta;
			if(timeLeft <= 0)
				moveAndReset();
		}
	}
	
	public void setDelay(int delay){
		this.delay = delay; 
	}

	private void moveAndReset() {
		mediator.moveSnake();
		timeLeft = delay;
	}
}
